package com.zqwh.yj.sdk.model;

import android.content.ContentResolver;
import android.content.Context;

import com.zqwh.yj.sdk.utils.LogUtils;

import ganlin.android.utils.JNI_GPIO_Utils;

/**
 * Created by eason.yang on 2017/8/21.
 */
public class RpModelImpl implements SmdtModel {
    private Context mContext;
    private JNI_GPIO_Utils rpGpioUtils;

    public RpModelImpl(Context context) {
        this.mContext = context;
        rpGpioUtils = new JNI_GPIO_Utils();
        rpGpioUtils.gpioInit();
    }

    @Override
    public int unlock(int gpio) {
        return 0;
    }

    @Override
    public int lock(int gpio) {
        return 0;
    }

    @Override
    public int getDoorStatus(int gpio) {
        return 0;
    }

    @Override
    public int setInternalGpioDirection(int io, int direction, int def) {
        return 0;
    }

    @Override
    public int getInternalGpioDirection(int io) {
        return 0;
    }

    @Override
    public int setInternalGpioValue(int io, int value) {
        return 0;
    }

    @Override
    public int getInternalGpioValue(int io) {
        return 0;
    }

    @Override
    public int setExternalGpioDirection(int io, int direction, int def) {
        return 0;
    }

    @Override
    public int getExternalGpioDirection(int io) {
        return 0;
    }

    @Override
    public int setExternalGpioValue(int io, int value) {
        if (io == 0){
            if (value == 0){
                rpGpioUtils.setLedWifi(JNI_GPIO_Utils.LedStatusEnum.STATUS_ON);
            }else {
                rpGpioUtils.setLedWifi(JNI_GPIO_Utils.LedStatusEnum.STATUS_OFF);
            }
        }else if (io == 1){
            if (value == 0){
                rpGpioUtils.setLedCom(JNI_GPIO_Utils.LedStatusEnum.STATUS_ON);
            }else {
                rpGpioUtils.setLedCom(JNI_GPIO_Utils.LedStatusEnum.STATUS_OFF);
            }
        }else if (io == 4){
            if (value == 0){
                rpGpioUtils.setRelay2(JNI_GPIO_Utils.RelayStatusEnum.STATUS_ON);
            }else if (value == 1){
                rpGpioUtils.setRelay2(JNI_GPIO_Utils.RelayStatusEnum.STATUS_OFF);
            }
        }
        return 0;
    }



    @Override
    public int getExternalGpioValue(int io) {
        if (io == 5){
            JNI_GPIO_Utils.TriggerStatusEnum statusEnum = rpGpioUtils.getTrigger2();
            return statusEnum.getValue();
        }
        return 0;
    }

    @Override
    public void setBrightness(ContentResolver resolver, int brightness) {

    }

    @Override
    public void setRotation(String rotationDegree) {

    }

    @Override
    public void setLcdBackLight(int value) {
    }

    @Override
    public void reboot() {
    }

    @Override
    public int watchDogEnable() {
        return 0;
    }

    @Override
    public int watchDogDisable() {
        return 0;
    }

    @Override
    public int watchDogFeed() {
        return 0;
    }

    @Override
    public void execSuCmd(String command) {
    }

    @Override
    public void rodControl(String status) {
        if (status.equals("right")){
            rpGpioUtils.setMotor(JNI_GPIO_Utils.MotorStatusEnum.STATUS_FORWARD);
        }else if (status.equals("left")){
            rpGpioUtils.setMotor(JNI_GPIO_Utils.MotorStatusEnum.STATUS_REVERSE);
        }else if (status.equals("close")){
            rpGpioUtils.setMotor(JNI_GPIO_Utils.MotorStatusEnum.STATUS_BRAKE);
        }
    }
}
